package com.steven.concurrency.example.singleton;

import com.steven.concurrency.annoations.Recommend;
import com.steven.concurrency.annoations.ThreadSafe;


/**
 * 枚举模式
 */
@ThreadSafe
@Recommend
public class EnumSingleton {

    private EnumSingleton(){

    }
    public static EnumSingleton getinstance(){
        return Singletons.INSTANCE.getSingleton();
    }
    private enum Singletons{
        INSTANCE;
       private  EnumSingleton singleton;

       //jvm保证此方法只调用一次
        Singletons(){
            singleton = new EnumSingleton();
        }
        public EnumSingleton getSingleton(){
            return singleton;
        }
    }
}
